﻿using System;
using System.Reflection;

class Person
{
    public string Name { get; set; }

    // 无参构造方法
    public Person()
    {
        Name = "Default";
    }

    // 有参构造方法
    public Person(string name)
    {
        Name = name;
    }

    public void SayHello()
    {
        Console.WriteLine($"Hello, my name is {Name}.");
    }
}

class Program
{
    static void Main()
    {
        Type personType = typeof(Person);

        object person1 = Activator.CreateInstance(personType);
        Console.WriteLine($"Person1: {((Person)person1).Name}");

        ConstructorInfo ctor = personType.GetConstructor(new Type[] { typeof(string) });
        object person2 = ctor.Invoke(new object[] { "Alice" });
        Console.WriteLine($"Person2: {((Person)person2).Name}");

        MethodInfo method = personType.GetMethod("SayHello");
        method.Invoke(person2, null);
    }
}
